package org.xinjiang.data.migration.hainan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xinjiang.data.migration.common.utils.query.Queries;
import org.xinjiang.data.migration.hainan.convert.CrimeRelationshipsConvert;
import org.xinjiang.data.migration.hainan.dto.req.CrimeNameQueryDTO;
import org.xinjiang.data.migration.hainan.dto.req.CrimeRelationshipsQueryDTO;
import org.xinjiang.data.migration.hainan.dto.res.CrimeNameResultDTO;
import org.xinjiang.data.migration.hainan.dto.res.CrimeRelationshipsResultDTO;
import org.xinjiang.data.migration.hainan.entity.CrimeNameEntity;
import org.xinjiang.data.migration.hainan.entity.CrimeRelationshipsEntity;
import org.xinjiang.data.migration.hainan.mapper.CrimeRelationshipsMapper;
import org.xinjiang.data.migration.hainan.service.ICrimeRelationshipService;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CrimeRelationshipServiceImpl extends ServiceImpl<CrimeRelationshipsMapper, CrimeRelationshipsEntity> implements ICrimeRelationshipService {

    @Autowired
    private CrimeRelationshipsConvert crimeRelationshipsConvert;

    @Override
    public List<CrimeRelationshipsResultDTO> findList(CrimeRelationshipsQueryDTO dto) {
        return list(wrapper(dto)).stream().map(crimeRelationshipsConvert::convert).collect(Collectors.toList());
    }


    private LambdaQueryWrapper<CrimeRelationshipsEntity> wrapper(CrimeRelationshipsQueryDTO query) {
        LambdaQueryWrapper<CrimeRelationshipsEntity> wrapper = Queries.lambda();
        Queries.accept(query.getId(), v -> wrapper.eq(CrimeRelationshipsEntity::getId, v));
        Queries.accept(query.getCorrectorIdList(), v -> wrapper.in(CrimeRelationshipsEntity::getCorrectorId, v));
        Queries.accept(query.getTypeCrime(), v -> wrapper.eq(CrimeRelationshipsEntity::getTypeCrime, v));
        Queries.accept(query.getSpecificCharges(), v -> wrapper.like(CrimeRelationshipsEntity::getSpecificCharges, v));
        return wrapper;
    }
}
